package com.cnzz.site1255174697.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cnzz.site1255174697.Const;
import com.cnzz.site1255174697.R;
import com.cqyanyu.yanyu.model.EventEntity;
import com.cqyanyu.yanyu.view.FontIconView;
import com.cqyanyu.yanyu.view.XBaseViewHolder;

import org.greenrobot.eventbus.EventBus;

/**
 * 分类--默认排序
 */
public class ChoiceListAdapter extends BaseAdapter {

    private Context context;
    String[] names = {"默认", "价格从高到低", "价格从低到高"}; //, "上新时间"
    private int select = -1;

    public ChoiceListAdapter(Context context) {
        this.context = context;
    }

    public String[] getNames() {
        return names;
    }

    public void setNames(String[] names) {
        this.names = names;
    }

    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_choice, null);
        }
        TextView tvTitle = XBaseViewHolder.get(convertView, R.id.tv_title);
        FontIconView fontIconView = XBaseViewHolder.get(convertView, R.id.fv_gou);
        tvTitle.setText(names[position]);

        if (select == position) {
            fontIconView.setVisibility(View.VISIBLE);
        } else {
            fontIconView.setVisibility(View.GONE);
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventEntity eventEntity = new EventEntity();
                eventEntity.type = Const.JUMP_CLICK_LIST;
                eventEntity.id = position;
                eventEntity.data = names;
                EventBus.getDefault().post(eventEntity);
            }
        });
        return convertView;
    }

    public int getSelect() {
        return select;
    }

    public void setSelect(int select) {
        this.select = select;
        notifyDataSetChanged();
    }
}
